<template>
	<!-- 添加仓库 -->
	<view>
		<view class="boxtop">
			<text class="text">{{title}}</text>
		</view>
		<view class="boxhead">
			<view class="item">
				<text class="text">仓库名称:&nbsp;</text>
				<input class="input" type="text" v-model="wname" placeholder="请输入仓库名称">
			</view>
			<view class="item">
				<text class="text">仓库地址:&nbsp;</text>
				<input class="input" type="text" v-model="adress" placeholder="请输入仓库地址">
			</view>
			<view class="item1">
				<text class="text">仓库负责人:</text>
				<select v-model="empname">
					<option disabled value="">请选择仓库负责人</option>
					<option v-for="dept in options" :key="dept.empid" :value="dept.empid">{{dept.empid}}{{dept.empname}}</option>
				</select>
			</view>
			<view class="item">
				<text class="text1">备注:</text>
				<textarea class="textarea" v-model="title" placeholder="其他信息"></textarea>
			</view>
			<button @click="instdata">确认添加</button>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:'添加仓库',options:[],select:'',
				wname:'',adress:'',empname:'',title:''
			}
		},
		onLoad() {
			this.getdata();
		},
		methods: {
			async getdata(){
				var emid = this.dptemid;
				const res = await this.Request({
					url:'api/employee/getdptname',
					method:'POST',
					data:{departmentid:3}
				})
				this.options = res.data
			},
			async instdata(){
				if(this.wname.replace(/\s*/g,"").length == 0 || 
				   this.adress.replace(/\s*/g,"").length == 0 ||
				   this.empname == ''){
					uni.showToast({
						icon:"error",
						title:'内容不可为空'
					})
				} else {
					var arr = [];
					const res = await this.Request({
						url:'api/warehouse/getwarname'
					})
					for(let i= 0;i<res.data.length;i++) {
					     arr[i] = res.data[i].wname;
					}
					if(arr.includes(this.wname)){
						uni.showToast({
							icon:"error",
							title:'仓库名称已存在'
						})
					} else {
						const res = await this.Request({
							url:'/api/warehouse/waradd',
							method:'POST',
							data:{wname:this.wname,waremid:this.empname,adress:this.adress,title:this.title}
						})
						if(res.data.affectedRows=1){
							uni.showToast({
								title: '添加成功'
							})
							setTimeout(() => {
								uni.reLaunch({
									url:'/pages/public/warehouse/warment'
								})
							},500)
						}
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.boxtop{
		width: 100%;
		background-color: #efefef;
		display: flex;
		border-bottom: 1px solid #ccc;
		.text{
			margin: 5px 0 5px 5px;
			font-size: 110%;
			font-weight: 700;
			color: #d3d3d3;
		}
	}
	.boxhead{
		.item{
			display: flex;
			margin-top: 10px;
			border-top: 1px solid #a2a2a2;
			border-bottom: 1px solid #a2a2a2;
			border-radius: 10px;
			.text{
				margin: 10px 0 10px 20px;
				font-size: 17px;
				font-weight: 700;
			}
			.text1{
				display: block;
				width: 100px;
				margin: 10px 0 10px 20px;
				font-size: 17px;
				font-weight: 700;
			}
			.input{
				margin: 10px 0 10px 36px;
				font-size: 15px;
				font-weight: 500;
				border-bottom: 2px solid #a2a2a2;
			}
			.textarea{
				margin-left: -20px;
				border: 2px solid #a2a2a2;
				border-radius: 10px;
			}
		}
		.item1{
			display: flex;
			margin-top: 10px;
			border-top: 1px solid #a2a2a2;
			border-bottom: 1px solid #a2a2a2;
			border-radius: 10px;
			select{
				margin: 2px 0 2px 20px;
				width: 170px;
				border-radius: 10px;
			}
			.text{
				margin: 10px 0 10px 20px;
				font-size: 17px;
				font-weight: 700;
			}
			.input{
				margin: 10px 0 10px 20px;
				font-size: 15px;
				font-weight: 500;
				border-bottom: 2px solid #a2a2a2;
			}
		}
		button{
			width: 50%;
			margin-left: 25%;
			margin-top: 40px;
			background-color: s#fff5a6;
		}
	}
</style>
